<template>
  <div class="">
    <van-uploader class="uploadimg" :after-read="afterRead" :max-count="1" @delete="deleteimg()" multiple v-model="fileList"/>
  </div>
</template>
<script>
import {upload} from '@/api/home.js'
export default {
  props: {
    no: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      fileList: []
    }
  },


  methods: {
    deleteimg() {
      this.$emit('deleteimage', '')
    },
    afterRead(file) {
      file.status = 'uploading';
      file.message = '上传中...';
      let form = new FormData()
      form.append('image',file.file)
      upload(form).then((res) => {
        if (res.err_code === 200) {
          file.status = 'done';
          file.message = '上传成功';
          this.$emit('uploadimg', res.data.img_url)
        }
      }).catch((e) => { console.log(e) })
    }
  }
}
</script>

<style scpoed>
.top32{
  margin-top: 32px;
}
.uploadimg{
  width: 131px;
  height: 177px;
  margin-top: 13.5px;
}
</style>
<style>
.van-uploader__wrapper,.van-uploader__upload{
  width: 131px;
  height: 177px;
  background: #fff;
  display: flex;
  align-items: center;
}
.van-uploader__preview,.van-uploader__file{
  width: 131px;
  height: 177px;
  margin:0;
}
.van-uploader__preview-image{
  margin: 0 auto;
}
.van-uploader__preview{
  display: flex;
  align-items: center;
}
</style>
